package com.itcast.springboot.waste_recovery.common;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Author 郭泽鹏
 * @Date 2020/8/17 23:35
 * @Version 1.0
 * @Description 公共返回格式类
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CommonResult<T> {

    private Integer code;

    private String msg;

    private T data;

//    public CommonResult(Integer code, String msg) {
//        this.code = code;
//        this.msg = msg;
//        this.data = null;
//    }

    public CommonResult(CommonResultCode code) {
        this.code = code.code;
        this.msg = code.msg;
        this.data = null;
    }

    public CommonResult(CommonResultCode code, T data) {
        this.code = code.code;
        this.msg = code.msg;
        this.data = data;
    }

    public CommonResult(Integer code,String msg) {
        this.code = code;
        this.msg = msg;
    }

    /**
     * 操作成功
     */
    public static CommonResult CommonSuccess(){
        return new CommonResult(CommonResultCode.CommonSuccess);
    }

    /**
     * 身份已经认证过
     */
    public static CommonResult CommonAuthed(){
        return new CommonResult(CommonResultCode.CommonAuthed);
    }

    /**
     * 操作失败
     */
    public static CommonResult CommonFail(){
        return new CommonResult(CommonResultCode.CommonFail);
    }

    /**
     * 未登录
     */
    public static CommonResult CommonUnlogin(){
        return new CommonResult(CommonResultCode.CommonUnlogin);
    }

    /**
     * 未授权
     */
    public static CommonResult CommonUnauth(){
        return new CommonResult(CommonResultCode.CommonUnauth);
    }

    /**
     * 登录失败
     */
    public static CommonResult CommonLoginFail(){
        return new CommonResult(CommonResultCode.CommonLoginFail);
    }
}
